package club.dataresources.service.impl;

import club.dataresources.bo.BarberWorkTimeBo;
import club.dataresources.entity.BarberWorkTime;
import club.dataresources.entity.BarberWorkTimeExample;
import club.dataresources.mapper.BarberWorkTimeMapper;
import club.dataresources.service.BarberWorkTimeService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author
 * @create 2018-11-12 0:36
 **/
@Service
public class BarberWorkTimeServiceImpl implements BarberWorkTimeService{
    @Autowired
    private BarberWorkTimeMapper barberWorkTimeMapper;

    @Override
    public boolean addBarberWorkTime(BarberWorkTime barberWorkTime) throws Exception {
        return barberWorkTimeMapper.insertSelective(barberWorkTime)==1;
    }

    @Override
    public boolean removeBarberWorkTime(Integer barberId) throws Exception {
        return barberWorkTimeMapper.deleteByPrimaryKey(barberId)==1;
    }

    @Override
    public boolean updateBarberWorkTime(BarberWorkTime barberWorkTime) throws Exception {
        return barberWorkTimeMapper.updateByPrimaryKeySelective(barberWorkTime)==1;
    }

    @Override
    public BarberWorkTime findBwtByBarberId(Integer barberId) throws Exception {
        return barberWorkTimeMapper.selectByPrimaryKey(barberId);
    }

    /**
     * 分页列表
     * @param page
     * @param rows
     * @param barberWorkTime
     * @return
     * @throws Exception
     */
    @Override
    public Page<BarberWorkTime> listBarberWorkTime(Integer page, Integer rows, BarberWorkTime barberWorkTime) throws Exception {
        PageHelper.startPage(page, rows);
        BarberWorkTimeExample example = new BarberWorkTimeExample();
        BarberWorkTimeExample.Criteria criteria = example.createCriteria();
        criteria.andBarberIdIsNotNull();
        return barberWorkTimeMapper.selectByExample(example);
    }

    /**
     * 获取所有理发师的工作时间表
     * @return
     * @throws Exception
     */
    @Override
    public List<BarberWorkTimeBo> getAllBarberWorkerTime(int page,int rows) throws Exception {
        return barberWorkTimeMapper.getAllBarberWorkerTime(page,rows);
    }
}
